<?php
namespace jy_caigou;
defined('BY_JYA') or exit('error');
/*
	分销佣金
	分销插件所有金额字段均保存整形，精确到分。显示时，除以100然后保留两位小数即可
	佣金比例字段保存整形，值为万分数，相当于百分数的精确到小数点后2位。即展示到前端时，需要除以100，换算成百分数显示
*/
class member extends \plugin{
	public function checklogin($storeid='',$area_agentid='',$area_code='',$merchid=0){
		global $_AR;
		if(!$_SESSION['uid']){
			$_SESSION['forward_url']=$_AR['access_json'];
			model('core/core')->checklogin();
		}else{
			$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id'));
			if(empty($member)){
				model('core/member')->logout();
				model('core/core')->checklogin('jy_caigou/member.index/');
			}else{
				$user=pdo_get('jy_weishop_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id'));
				if(!$user['id']){
					$insert=array(
						'mid'=>$_SESSION['uid'],
						'uniacid'=>$_SESSION['uniacid'],
						'storeid'=>$storeid?:$_SESSION['storeid'],
						'merchid'=>$merchid,
						'area_agentid'=>$area_agentid?:$_SESSION['area_agentid'],
						'area_code'=>$area_code?:$_SESSION['area_code'],
						'createtime'=>TIMESTAMP,
					);
					model('jy_weishop/member')->register($insert);
					exi('','','jy_caigou/checktype/');
				}elseif(!$user['merchid'] && $merchid){
					pdo_update('jy_weishop_member',array('merchid'=>$merchid),array('id'=>$user['id'],'uniacid'=>$_SESSION['uniacid']));
				}
			}
		}
	}
}